package com.ziq.base.base.hilt

import com.ziq.base.base.ManifestParser
import com.ziq.base.manager.RetrofitManager
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object AppModule {
    //    @Binds     //@Binds 也是提供 实现的一种凡是 与@Provides 类似， 把入参的实现直接 返回
    //    abstract IRepositoryManager provideRepositoryManager(RetrofitManager repositoryManager);

//    @Singleton
//    @Provides
//    fun provideRetrofitManager(): RetrofitManager {
//        return RetrofitManager()
//    }

    @Singleton
    @Provides
    fun provideGlobalConfigModule(manifestParser: ManifestParser): GlobalConfigModule {
        val list = manifestParser.parse()
        return getGlobalConfigModule(list)
    }

    private fun getGlobalConfigModule(modules: List<ConfigModule>): GlobalConfigModule {
        val globalConfigModule = GlobalConfigModule()
        globalConfigModule.configModules.clear()
        globalConfigModule.configModules.addAll(modules)
        //遍历 ConfigModule 集合, 给全局配置 GlobalConfigModule 添加参数
        for (module in modules) {
            module.applyCustomConfig(globalConfigModule)
        }
        return globalConfigModule
    }
}